home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / hard / hack / i2clib40.lha / i2clib40 / Developer / i2c_library.h < prev    next >
C/C++ Source or Header  |  1998-08-30  |  4KB  |  109 lines

  1. /*
  2. **     $Author: Bipsen $
  3. **     $Filename: i2c_library.h $
  4. **     $Release: 3.00 $
  5. **     $Revision: 40.0 $
  6. **     $Date: 1998/08/11 22:17:48 $
  7. **
  8. **     Headerfile to include in programs using i2c.library
  9. **
  10. */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/libraries.h>
  14.  
  15. extern struct Library *I2C_Base;
  16.  
  17. /*--- functions in v37.0 or higher ---*/
  18. #pragma libcall I2C_Base AllocI2C 1E 9002
  19. #pragma libcall I2C_Base FreeI2C 24 0
  20. #pragma libcall I2C_Base SetI2CDelay 2A 1
  21. #pragma libcall I2C_Base InitI2C 30 0
  22. #pragma libcall I2C_Base SendI2C 36 91003
  23. #pragma libcall I2C_Base ReceiveI2C 3C 91003
  24. /*--- functions in v38.0 or higher ---*/
  25. #pragma libcall I2C_Base GetI2COpponent 42 0
  26. /*--- functions in v39.0 or higher ---*/
  27. #pragma libcall I2C_Base I2CErrText 48 1
  28. #pragma libcall I2C_Base ShutDownI2C 4E 0
  29. #pragma libcall I2C_Base BringBackI2C 54 0
  30.  
  31. /* Proto-types for functions */
  32.  
  33. BYTE AllocI2C(UBYTE Delay_Type,char *Name);
  34. void FreeI2C(void);
  35. ULONG SetI2CDelay(ULONG ticks);
  36. void InitI2C(void);
  37. ULONG SendI2C(UBYTE addr, UWORD number, UBYTE i2cdata[]);
  38. ULONG ReceiveI2C(UBYTE addr, UWORD number, UBYTE i2cdata[]);
  39. STRPTR GetI2COpponent(void);
  40. STRPTR I2CErrText(ULONG errnum);
  41. void ShutDownI2C(void);
  42. BYTE BringBackI2C(void);
  43.  
  44. /* Definitions for return-codes etc. */
  45.  
  46. /* If you call SetI2CDelay only to read the delay, not change it: */
  47. #define I2CDELAY_READONLY 0xffffffff    /* V39+ ! */
  48.  
  49. /* Type of delay to pass to AllocI2C (obsolete in V39+, see docs): */
  50. #define DELAY_TIMER 1   /* Use timer.device for SCL-delay  */
  51. #define DELAY_LOOP  2   /* Use for/next-loop for SCL-delay */
  52.  
  53. /* Allocation Errors */
  54. /* (as returned by AllocI2C, BringBackI2C, or found in the middle high */
  55. /* byte of the error codes from V39's SendI2C/ReceiveI2C) */
  56. enum {
  57.     I2C_OK=0,               /* Hardware allocated successfully */
  58.     I2C_PORT_BUSY,          /* \_Allocation is actually done in two steps: */
  59.     I2C_BITS_BUSY,          /* / port & bits, and each step may fail */
  60.     I2C_NO_MISC_RESOURCE,   /* Shouldn't occur, something's very wrong */
  61.     I2C_ERROR_PORT,         /* Failed to create a message port */
  62.     I2C_ACTIVE,             /* Some other I2C client has pushed us out */
  63.     I2C_NO_TIMER            /* Failed to open the timer.device */
  64.     };
  65.  
  66. /* I/O Errors */
  67. /* (as found in the middle low byte of the error codes from V39's */
  68. /* SendI2C/ReceiveI2C) */
  69. enum {
  70.     /*I2C_OK=0,*/       /* Last send/receive was OK */
  71.     I2C_REJECT=1,       /* Data not acknowledged (i.e. unwanted) */
  72.     I2C_NO_REPLY,       /* Chip address apparently invalid */
  73.     SDA_TRASHED,        /* SDA line randomly trashed. Timing problem? */
  74.     SDA_LO,             /* SDA always LO \_wrong interface attached, */
  75.     SDA_HI,             /* SDA always HI / or none at all? */
  76.     SCL_TIMEOUT,        /* \_Might make sense for interfaces that can */
  77.     SCL_HI,             /* / read the clock line, but currently none can. */
  78.     I2C_HARDW_BUSY      /* Hardware allocation failed */
  79.     };
  80.  
  81. /* ======================================================================== */
  82. /* === I2C_Base =========================================================== */
  83. /* ======================================================================== */
  84. /*
  85.  * Starting with V40, i2c.library exposes some statistics counters, and a
  86.  * hint what kind of hardware implementation you are dealing with, in its
  87.  * base structure. These data weren't present in any of the previous
  88.  * releases, so check the lib version before you try to read them.
  89.  */
  90.  
  91. /* This structure is READ ONLY, and only present in V40 or later! */
  92. struct I2C_Base
  93.     {
  94.     struct Library LibNode;
  95.     ULONG SendCalls;        /* calls to SendI2C */
  96.     ULONG SendBytes;        /* bytes actually sent */
  97.     ULONG RecvCalls;        /* calls to ReceiveI2C */
  98.     ULONG RecvBytes;        /* bytes actually received */
  99.     ULONG Lost;             /* calls rejected due to resource conflicts */
  100.     ULONG Unheard;          /* calls to addresses that didn't reply */
  101.     ULONG Overflows;        /* times a chip rejected some or all of our data */
  102.     ULONG Errors;           /* errors caused by hardware/timing problems */
  103.     UBYTE HwType;           /* implementation: 0=par, 1=ser, 2=disk, 3=card */
  104.  
  105.     /* The data beyond this point is private and is different between
  106.      * most of the various i2c.library implementations anyway.
  107.      */
  108.     };
  109.